#include <bits/stdc++.h>
using namespace std;
const int N=4e5+1;
int n,x,y,ans,fa[N],siz[N],siz2[N];
int getf(int x)
{
	if(x==fa[x])	return x;
	return fa[x]=getf(fa[x]);
}
int main()
{
	freopen("pairint.in","r",stdin);
	freopen("pairint.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	for(int i=1;i<=2*n;i++)
	{
		fa[i]=i;
		siz[i]=1;
	}
	for(int i=1;i<=n;i++)
	{
		cin>>x>>y;
		x=getf(x);
		y=getf(y);
		fa[x]=y;
		if(x!=y)
		{
			siz[y]+=siz[x];
			siz2[y]+=siz2[x];
		}
		siz2[y]++;
	}
	ans=2*n;
	for(int i=1;i<=2*n;i++)
		if(i==fa[i]&&siz[i]>siz2[i])
			ans--;
	cout<<ans;
	return 0;
}
